// import ListViewPage from '@page/list-view-page';
import { observable, action, toJS } from 'mobx';
import { Tools,Bubble } from 'weaver-mobile';
import { ListPage, ListViewPage, Form, Comment, Reply , ListEditable, Upload, RouteLayout, SelectPage, MapPage, Browser } from 'weaver-mobile-page';
import * as API_LIST from '../../api/meetingBase';
import * as API from '../../api/signInfo';
import moment from 'moment';
import _ from 'lodash'
import { Base64 } from 'js-base64';
const getLabel = Tools.getLabel;


export default class ViewMeetingStore {
  //-----------全局使用 sessionStorage  start----------
  @observable meetingTopicDefaultValue = 0;
	@observable meetingServiceDefaultValue = 0;
	@observable topicViewActive = false;
	@observable serviceViewActive = false;
  @observable tabs = '';
  @observable tabPanes = [];
  @observable meetingName = '';
  @observable showTopic = false;
  @observable showService = false;
  @observable showMeetingSeat = false;
  @observable isDecision = false;//作用:打开isDiscuss=1相关交流的情况下,判断是否有会议决议tab页签,好定位相关交流页签的位置
  @observable renderToDecision = false;//作用:打开isDiscuss=1相关交流的情况下,判断是否有会议决议tab页签,好定位相关交流页签的位置
  @observable oldSecretLevel = '';
  @observable baseDocFlowColumn = [];//会议信息中的文档流程字段,密级需要加参数
  @observable topicDocFlowColumn = [];//会议议程中的文档流程字段,密级需要加参数
  @observable serviceDocFlowColumn = [];//会议服务中的文档流程字段,密级需要加参数
  @observable serviceKeycol = '';//会议服务中记录需要校验的字段名称，方便做服务校验时将其取出
  @observable uploadParams = {}; //上传附件默认参数
  @observable uploadKeys = [];
  @observable accessoryBaseInfo = {};
  @observable nowValue=this.dateFormat("YYYY-mm-dd HH:MM:SS", new Date());
  //会议ID
  @observable meetingId = '';
  @observable meetingType = '';
  @observable noRight = false;
  @observable noData = false;
  @observable noSecretRight = false;
  @observable getBaseDetail = false;
  @observable previewmeetingTab = 0;
  @observable onlyFlowCreate = 0;//是否只允许使用流程新建会议
  @observable hideCreateEntry = 0;//是否隐藏新建入口,只能通过流程模块新建会议
  @observable workflowBaseIds = '';//新建会议流程使用的workflow_base对应的id
  @observable addRequestUrlParams  =  '';
  @observable requestFieldIds={};//在从会议室使用情况新建的时候对应只有一条流程打开时候需要带出参数
  //index页面有一个hasCaller,是根据会议类型变更的时候判断的,这里加一个是在点击编辑按钮的时候取得会议类型来进行判断的
  @observable hasCaller = false;
  //控制按钮[view:查看会议信息,create:新建的时候,edit:编辑的时候,change:变更的时候,save:保存的时候,submit:新建提交的时候]
  //[reSubmit2:草稿信息页面提交按钮]
  @observable type = '';
  //-----------全局使用 sessionStorage  end----------
  @observable onLoading = false;
  //-----------会议信息  start----------
  @observable form = new Form.Store({
    route: '/calendar/detail/index'
  });
  @observable btns = ''
  @observable canset = false
  //是否为正常会议,目的是判断tab页有多少个,用作跳转
  @observable isNormal=true
  @observable roomPlanSelectDate=''
  @observable begintime=''
  @observable endtime=''
  @observable roomid = ''
  //[reSubmit2:草稿信息页面提交按钮]
  @observable openAccess = '';
  @observable createParams ={}
  @observable urlCreateParams = {};
  //-----------会议信息  end----------

  //-----------参会回执用  start----------
  @observable hrmList = new ListPage.Store();
  @observable mobileshowtemplateHrm = '';
  @observable crmList = new ListPage.Store();
  @observable mobileshowtemplateCrm = '';
  @observable otherMemberList = new ListPage.Store({ route: '/member/otherMemberData' });
  @observable otherCrmList = new ListPage.Store({ route: '/member/otherMemberData' });
  @observable receiptForm = new Form.Store({
    route: '/detail/member/memberData/allMember/receiptForm'
  });
  @observable mobileshowtemplateOther = '';
  //跳转到全部人员tab还是参加人员tab.......
  @observable memberPage = 0;
  //{0:应到人数,1:确定参加,2:不参加,3:未提交}
  @observable selectType = 0;
  //是客户还是人员
  @observable memberType = 0;
  @observable memberDetailCount = {};
  @observable othermembers = '';
  @observable othersremark = '';
  //meeting_member2中的id
  @observable recordId = '';
  //在跳转receiptForm的时候判断是查看还是编辑
  @observable isPreview = '1';
  //是否有权限进行编辑回执页面
  @observable canEdit = false;
  //因为参会回执进入form后的路由不同,所以导致路由跳转有问题,现在动态修改路由
  @observable prePathName = '';

  //信息页面 canView:是否看看  canSubmit:提交回执  canEdit:是否重新提交
  @observable showReceipt = {};


  @observable allCrmData = {}
  @observable crmReceiptList = new ListPage.Store();
  @observable crmReceiptEditable = new ListEditable.Store({ route: '/detail/member/memberData/allMember/receiptForm' });
  @observable crmReceiptInitialData = [];
  @observable crmReceiptData = [];
  @observable crmReceiptConditions = [];

  //-----------参会回执用  end----------

  //-----------会议签到  start----------
  @observable signList = new ListPage.Store();
  @observable lastlySignList = new ListPage.Store();
  //跳转到应到人数tab还是已签到tab.......
  @observable signPage = 0;
  //{0:应到人数,1:确定参加,2:不参加,3:未提交}
  @observable signSelectType = 0;
  //是客户还是人员
  @observable signDetailCount = [];
  //二维码
  @observable qrCode = '';
  //-----------会议签到  end----------

  //-----------会议签退  start----------
  @observable isSignOut = false; 
  

  //-----------会议签退  end----------

  //-----------会议议程  start----------
  @observable topicList = new ListPage.Store({ route: '/calendar/detail/topicData' });
  //-----------会议议程  end----------

  //-----------会议服务  start----------
  // @observable serviceList = new ListViewPage.Store();
  @observable serviceList = new ListPage.Store({ route: '/calendar/detail/serviceData' });
  //-----------会议签到  end----------

  //-----------相关交流  start----------
  @observable userName = '';
  @observable pageSize = 10;
  @observable pageNum = 0;
  @observable replyVisible = false;
  @observable comment = new Comment.Store({
    getComment: this.getComment,
  });
  @observable attachList = [];
  @observable reply = new Reply.Store({getAttachList: this.getReplyAttachList,getAtConfig: this.getAtConfig });
  @observable exchangeListStore = new ListPage.Store();
  //-----------相关交流  end----------

  //-----------会议分享  start----------
  @observable isfromchatshare = 0;
  @observable sharer = 0;
  //-----------会议分享  end----------
  @observable mapPage = new MapPage.Store({ route: '/calendar/detail/sign/signMap/viewMap' });
  //-----------会议决议  start----------
  @observable decisionForm = new Form.Store({
    route: '/calendar/detail/decision/index'
  });
  //会议新建签到
  @observable signCreateForm = new Form.Store({
    route: '/calendar/detail/signcreate'
  });
  @observable isView = '0'
  @observable allDecisionData = {}
  @observable decisionList = new ListPage.Store();
  @observable decisionistEditable = new ListEditable.Store({ route: '/calendar/detail/decision/index' });
  @observable decisionInitialData = [];
  @observable decisionData = [];
  @observable decisionConditions = [];
  //-----------会议决议  end----------
  //-----------会议排座  start----------
  @observable seatForm = new Form.Store({
    route: '/calendar/detail/meetingSeatData'
  });
  @observable definedColor = '';//默认座位颜色
  @observable selfColor = '';//本人座位颜色
  @observable selfId = '';//本人ID
  @observable fieldList = {};//会议室控件
  @observable seatDatas = [];//占座信息
  @observable styleType = ''; // 桌型
  @observable seatConfMap = []
  @observable hrmNameMap = []
  //-----------会议排座  end----------
  // cx start
  @observable is_create = true;
  @observable is_topic = true;
  @observable is_service = true;
  @observable topic_list = new ListEditable.Store({ route: '/calendar/detail/topicData' });
  @observable topic_initialData = [];
  @observable topic_data = [];
  @observable topic_conditions = [];
  @observable service_list = new ListEditable.Store({ route: '/calendar/detail/serviceData' });
  @observable serivce_initialData = [];
  @observable serivce_data = [];
  @observable service_conditions = [];
  @observable tempUploadStore = {};
  @observable tempServiceUploadStore = {};
  //临时解决打开文档，流程问题
  @observable overWriteOpenDoc = false;
  @observable openDocFunc = window.openLink&&window.openLink.openDocument;
  @observable overWriteOpenWF = false;
  @observable openWFFunc = window.openLink&&window.openLink.openWorkflow;
  @observable selectPage = new SelectPage.Store({route: '/calendar/detail/index'});
  @observable remidOptions = []; // 提醒方式
  @observable loadding = false; 
  @observable checkBoxSelectpageStore = {};
  @observable checkBoxSelectpageValue = {};
  @observable meetingBeginDate = '';
  @observable meetingEndDate = '';

  // cx end
  
  // 为了满足无侵入开发部分-start
	@observable ecCallerVisible = true;  //  召集人显示
  @observable previewMeetingResultInfo = {};

  @observable customField = [];

  // 议程资料 安排时间-start
  @observable arrangeDateLayout = new RouteLayout.Store({ route: '/calendar/detail/topicData', id: 'arrangeDate' });
  @observable provideInfoLayout = new Browser.Store({ route: '/calendar/detail/topicData', id: 'provideInfoLayout'  });
  @observable videwDatumLayout = new Browser.Store({ route: '/calendar/detail/topicData', id: 'videwDatumLayout'  });
  @observable editTopicLayout = new Browser.Store({ route: '/calendar/detail/topicData', id: 'editTopicLayout'  });
  @observable arrangeDateForm = new Form.Store({ route: '/calendar/detail/topicData/arrangeDate' });
  @observable datumForm = new Form.Store({ route: '/calendar/detail/topicData/videwDatumLayout' });
  @observable topicDocList = [];
  @observable topicArrangeDates = [];
  @observable topicCurrentId = '';
  @observable topicType = 'view'; 
  @observable topicViewTopicConditions = [];
  @observable replySubmitLoading = false;
  @observable isLimitCreateMeetingBeginEndTime = false;
  // 议程资料 安排时间-end

  @observable topicConditionUploadKeys = []; // 议程中上传附件字段
  @observable serviceConditionUploadKeys = []; // 会议服务中上传附件字段

  @observable arrangeTopicParams = {
		arrangeTopic: 1
  };
  
  setUploadParams = (params) => {
    const uploadParams = toJS(this.uploadParams);
		Object.keys(params).forEach(key => {
      uploadParams[key] = {
				...uploadParams[key],
				...params[key]
			}
		})
		this.uploadParams = uploadParams;
  }
  
  cleanStore = ()=>{
    this.topic_list = new ListEditable.Store({ route: '/calendar/detail/topicData' });
    this.service_list = new ListEditable.Store({ route: '/calendar/detail/serviceData' });
    this.decisionistEditable = new ListEditable.Store({ route: '/calendar/detail/decision/index' });
    this.serviceList = new ListPage.Store({ route: '/calendar/detail/serviceData' });
    this.topicList = new ListPage.Store({ route: '/calendar/detail/topicData' });
    this.topic_data = [];
    this.serivce_data = [];
  }

  setUploadCommonParams = (params) => {
    const uploadParams = toJS(this.uploadParams);
    const uploadKeys = toJS(this.uploadKeys);
    uploadKeys.length > 0 && uploadKeys.map(key => {
    	uploadParams[key] = {
				...uploadParams[key],
				...params
			}
		})
    this.uploadParams = uploadParams;
  }
  
  setAccessoryBaseInfo = (params) => {
    const accessoryBaseInfoTemp = {...this.accessoryBaseInfo,...params};    
    this.accessoryBaseInfo = accessoryBaseInfoTemp;
  }

  addCustomField = (params = [])=>{
    this.customField = params
  }

	// 为了满足无侵入开发部分-end

  initMeeting = ()=>{
    this.noRight = false
    this.noData = false
    this.noSecretRight = false;
  }

  initTopicAndServiceData = ()=>{
    //初始化议程服务的初始数据
    this.serivce_initialData = [];
    this.topic_initialData = [];
  }

  @action
  setState = (params = {}, callback) => {
    Object.keys(params).forEach((key) => {
      this[key] = params[key];
    });
    typeof(callback) === 'function' && callback();
  }
  setOldSecretLevel = (val) => this.oldSecretLevel = val;
  @action
  initForm = (params = {}) => {
    this.form = new Form.Store({
      route: '/calendar/detail/index'
    });
  }

  getFormBrowserType = (domkey) => {
		const { conditioninfo } = this.form;
    let conditions = conditioninfo;
    let browserType = '';
    conditions.length!==0 && conditions.forEach(c => {
      c && c.items && c.items.forEach(fields => {
        if(fields.domkey[0] === domkey){
          browserType = fields.conditionType
        }
      })
    })
    return browserType;
  }
  
   getRequestParams = ()=>{
    API_LIST.getRequestParams().then((result) => {
      this.onlyFlowCreate=(result.onlyFlowCreate&&result.onlyFlowCreate) || 0;
      this.hideCreateEntry=(result.hideCreateEntry&&result.hideCreateEntry) || 0;
      this.workflowBaseIds=(result.workflowBaseIds&&result.workflowBaseIds) || '';
      this.requestFieldIds=(result.requestFieldIds&&result.requestFieldIds) || {};
      this.begintime = (result.beginTime&&result.beginTime) || '';
      this.endtime = (result.endTime&&result.endTime) || '';
      const localDate = moment(new Date()).format("YYYY-MM-DD")
      let urlParamsTemp = [];
      if(result.onlyFlowCreate == 1){
        result.requestFieldIds&&Object.keys(result.requestFieldIds).map((item)=>{
          if(item === 'begintime'){
            result.requestFieldIds.begintime&&result.requestFieldIds.begintime.map(item1=>{
              result.beginTime&&urlParamsTemp.push(`&${item1}=${result.beginTime}`)
            })
          }
          if(item === 'endtime'){
            result.requestFieldIds.endtime&&result.requestFieldIds.endtime.map(item1=>{
              result.endTime&&urlParamsTemp.push(`&${item1}=${result.endTime}`)
            })
          }
          if(item === 'beginDateTime'){
            result.requestFieldIds.beginDateTime&&result.requestFieldIds.beginDateTime.map(item1=>{
              result.beginTime&&urlParamsTemp.push(`&${item1}=${localDate} ${result.beginTime}`)
            })
          }
          if(item === 'endDateTime'){
            result.requestFieldIds.endDateTime&&result.requestFieldIds.endDateTime.map(item1=>{
              result.endTime&&urlParamsTemp.push(`&${item1}=${localDate} ${result.endTime}`)
            })
          }
        })
        this.addRequestUrlParams = urlParamsTemp.join('')
      }

    })
  }

  getPreview = (params, callback, callback2, is_Discuss) => {
    this.nowValue = this.dateFormat("YYYY-mm-dd HH:MM:SS", new Date());
    let pathstr = window.location.hash && window.location.hash.split('#')[1].split('?');
    pathstr[1] = pathstr[0];
    let curType = sessionStorage.getItem("type")
    params = { ...params,
      ismobile: 1
    };
    if(this.type === 'change'){
      params = { ...params,
        isChange: 1
      };
    }
    if(params.meetingid){
      this.topic_initialData = [];
      this.topic_data = [];
      this.serivce_initialData = [];
      this.serivce_data = [];
      this.get_Data({meetingid: params.meetingid}, 'service');
      this.get_Data({meetingid: params.meetingid}, 'topic');
      this.meetingid=params.meetingid;
    }
    if(params && (params.address === undefined || params.address === '')) {
			delete params.address;
    }
    this.loadding = true;
    if(this.type === 'create' || this.type === 'edit'  || this.type === 'change' ){
      API_LIST.getBaseFields(params).then((result) => {
        this.meetingTopicDefaultValue = result.meetingTopicDefaultValue;
			  this.meetingServiceDefaultValue = result.meetingServiceDefaultValue;
        this.loadding = false;
        this.selectPage = new SelectPage.Store({route: `${pathstr[1]}`});
        if (curType == 'create') {
          window.em && window.em.checkJsApi('changeTitle') && window.em.changeTitle({ title: getLabel(15008, '新建会议') })
        }
        if (curType == 'edit') {
          window.em && window.em.checkJsApi('changeTitle') && window.em.changeTitle({ title: getLabel(384486, '编辑会议') })
        }
        if (curType == 'change') {
          window.em && window.em.checkJsApi('changeTitle') && window.em.changeTitle({ title: getLabel(384487, '变更会议') })
        }
        if (result) {
          this.accessoryBaseInfo = result.accessoryBaseInfo;
          this.oldSecretLevel=result.secretLevel;
          this.baseDocFlowColumn = result.baseDocFlowColumn;
          this.tabs = result.tabs
          this.getTabPanes(result.tabs)
          this.form = new Form.Store({
            route: this.prePathName
          });
          this.hasCaller = result.hasCaller
          this.form.initForm(result.datas, this.prePathName);
          this.noRight = false;
          this.noData = false;
          this.noSecretRight = false;
          result.datas && result.datas.map((v) => {
            Object.prototype.toString.call(v.items) === '[object Array]' && v.items.map(res => {
              if(res.domkey[0] === 'remindTypeNew') {
                this.remidOptions = res.value === '' ? [] : res.value.split(',');
                this.form.updateField('remindTypeNew',res.value);
              } else if(res.conditionType === "SELECT" && res.detailtype == 2) { // 复选框
                this.checkBoxSelectpageStore = {
                  ...this.checkBoxSelectpageStore,
                  [res.domkey[0]]: new SelectPage.Store({route: `${pathstr[1]}`})
                };
                this.checkBoxSelectpageValue = {
                  ...this.checkBoxSelectpageValue,
                  [res.domkey[0]]: res.value === '' ? [] : res.value.split(',')
                };
                this.form.updateField(res.domkey[0],res.value);
              } else if(res.domkey[0] === 'meetingtype') {
                this.meetingType = res.value || '';
              }
              if(res.conditionType == 'UPLOAD'){
                this.uploadParams = {
                  ...this.uploadParams,
                  [res.domkey[0]]: {
                    autoUpload: res.autoUpload || true,
                    listType: res.listType || 'list',
                    limitType: res.limitType || '',
                    uploadUrl: res.uploadUrl || '',
                    maxUploadSize: res.maxUploadSize || 0,
                    mixUploadSize: res.mixUploadSize || 0,
                    viewAttr: res.viewAttr || 2,
                    showClearAll: res.showClearAll || false,
                    category: res.category || '',
                    errorMsg: res.errorMsg || '',
                    datas: res.datas || [],
                  }
                }
                this.uploadKeys = [...this.uploadKeys, res.domkey[0]]
              }
            })
          })
          if (callback) callback(true)
        }
      })
    }else if(this.type === 'view'){
      this.overWriteOpenWF = false;
      this.overWriteOpenDoc = false;
      API_LIST.getPreview(params).then((result) => {
        this.loadding = false;
          if (curType == 'view') {
            window.em && window.em.checkJsApi('changeTitle') && window.em.changeTitle({ title: getLabel(384485, '查看会议') })
          }
        this.previewMeetingResultInfo = result;
        if (result && result.error !== 'noright' && result.error !== 'noData' && result.error !== 'noSecretRight') {
          this.accessoryBaseInfo = result.base.accessoryBaseInfo;
          this.oldSecretLevel=result.secretLevel;
          this.tabs = result.tabs
          this.getTabPanes(result.tabs)
          this.subLength(result.base.meetingstatus)
          this.form.initForm(result.base.datas, '/calendar/detail/index');
          this.meetingId = params.meetingid
          this.showReceipt = {...result.base.showReceiptBtn}
          if(!is_Discuss) { //解决单页访问直接在相关交流页面时，不能置0，会导致翻页时有重复数据
            this.pageNum = 0;
          }
          // this.btns = result.base.btns
          this.canset = result.base.canset
          this.openAccess = result.base.openAccess&&result.base.openAccess
          this.hasCaller = result.hasCaller
          sessionStorage.setItem('meetingName',toJS(this.form.formData).name.value);
          sessionStorage.setItem('meetingId',params.meetingid)
          //判断文档和流程
          let dataTemp = result.base.datas;
          this.overWriteDocAndWF(dataTemp,params)
          this.meetingBeginDate=result.base.beginDate+" "+result.base.beginTime;
					this.meetingEndDate=result.base.endDate+" "+result.base.endTime;
          
          if (callback) callback(result.base.datas)
          
        }else if(result.error === 'noright'){
          this.noRight = true
          this.noData = false
          this.noSecretRight = false;
          this.tabs = []
          this.btns = []
        }else if(result.error === 'noData'){
          this.noRight = false
          this.noData = true
          this.noSecretRight = false;
          this.tabs = []
          this.btns = []
        }else if(result.error === 'noSecretRight'){
          this.noRight = false
          this.noData = false
          this.noSecretRight = true;
          this.tabs = []
          this.btns = []
        }
      })
    }
  }

  getTabPanes = (tabs) => {
    let type = this.type
    let tabArray = [];
    let tempTabs = [];
    let pathArr = [];
    let i = 1;
    if(!tabs && sessionStorage.meetingBaseTabs){
      tempTabs = JSON.parse(sessionStorage.meetingBaseTabs)
      return tempTabs;
    }else{
      pathArr.push('')
      if(true || tabs && tabs.base){
        tabArray.push( { title: getLabel(24249, '会议信息'),key:i });
        pathArr.push('/calendar/detail/index');
        i++;
      }
      if(tabs && tabs.topic && (type === 'view' || type === 'create' || type === 'edit')){
          tabArray.push( { title: getLabel(31327, '会议议程'),key:i });
          this.setState({showTopic:true})
          sessionStorage.setItem("showTopic",true)
          pathArr.push('/calendar/detail/topicData');
          i++;
      }
      if(tabs && tabs.service && (type === 'view' || type === 'create'  || type === 'edit')){
          tabArray.push( { title: getLabel(2107, '会议服务'),key:i });
          this.setState({showService:true})
          sessionStorage.setItem("showService",true)
          pathArr.push('/calendar/detail/serviceData')
          i++;
      }
      if(tabs && tabs.meetingseat && (type === 'view')){
        tabArray.push( { title: getLabel(506916, '排座信息'),key:i });
        this.setState({showMeetingSeat:true})
        sessionStorage.setItem("showMeetingSeat",true)
        pathArr.push('/calendar/detail/meetingSeatData')
        i++;
      }
      if(tabs && tabs.member && type === 'view'){
          tabArray.push( { title: getLabel(384782, '参会回执'),key:i });
          pathArr.push('/calendar/detail/member');
          i++;
      }
      if(tabs && tabs.sign && type === 'view'){
          tabArray.push( { title: getLabel(383592, '会议签到'),key:i });
          pathArr.push('/calendar/detail/sign');
          i++;
      }
      if(tabs && tabs.sign && type === 'create' || type === 'edit'){
        tabArray.push( { title: getLabel(383592, '会议签到'),key:i });
        pathArr.push('/calendar/detail/signcreate');
        i++;
    }
      if(tabs && tabs.discuss && type === 'view'){
          tabArray.push( { title: getLabel(15153, '相关交流'),key:i });
          pathArr.push('/calendar/detail/discussData');
          i++;
      }
      if(tabs && tabs.decision && type === 'view'){
        tabArray.push( { title: getLabel(2194, '会议决议'),key:i });
        this.isDecision = true;
        pathArr.push('/calendar/detail/decisionData');
        i++;
      }
      if(sessionStorage){
        if(tabArray.length>0){
          sessionStorage.setItem('meetingBaseTabs',JSON.stringify(tabArray))
          sessionStorage.setItem('meetingTabpath',JSON.stringify(pathArr))
        }
      }
      this.tabPanes = tabArray;
    }
    
  }

  getBtns=(params)=>{
    API_LIST.getBtns(params).then((result) => {
      this.btns = result.btns
    })
  }

  subLength = (status)=>{
    if(status === '0' || status === '1' || status === '3'){
      this.isNormal = false
      sessionStorage.setItem('isNormal',false)
    }else{
      this.isNormal = true
      sessionStorage.setItem('isNormal',true)
    }
  }

  setBaseDetail = (flg=false)=>{
    this.getBaseDetail=flg
  }

  setFilterReminder = (params) => {// 过滤先勾选提醒方式然后取消勾选后多余的参数
    if(params && params.remindTypeNew === '') {// 未勾选提醒方式
      params = {
        ...params,
        remindImmediately: '0',
        remindBeforeStart: '0',
        remindHoursBeforeStart: '0',
        remindTimesBeforeStart: '0',
        remindBeforeEnd: '0',
        remindHoursBeforeEnd: '0',
        remindTimesBeforeEnd: '0',
      };
    }
    return params;
  }



  //提交会议
  submitMeeting = (params,callback)=>{
    this.loadding = true;
    // 提醒方式未选,清除开始前和结束前数据
    params = this.setFilterReminder(params);
    return API_LIST.submitMeeting(params).then((result)=>{
      this.loadding = false;
      this.onLoading = false;
      if(result.status===true){
        this.meetingId = result.meetingid
        this.type = 'view';
        this.setBaseDetail(true)
        sessionStorage.setItem('type','view')
        sessionStorage.setItem('meetingId',result.meetingid)
        callback();
      }else{
        Bubble.error(result.error, 3);
      }
    })
  }

  //保存会议
  saveMeeting = (params,callback)=>{
    this.onLoading = false;
    this.loadding = true;
    params = this.setFilterReminder(params);
    API_LIST.saveMeeting(params).then((result) => {
      this.loadding = false;
      if(result.status===true){
        this.meetingId = result.meetingid
        this.type = 'view'
        this.setBaseDetail(true)
        sessionStorage.setItem('type','view')
        sessionStorage.setItem('meetingId',result.meetingid)
        callback();
      }else{
        Bubble.error('提交失败!', 3);
      }
      
    })
  }

  //编辑会议
  editMeeting = (params,callback)=>{
    this.loadding = true;
    params = this.setFilterReminder(params);
    API_LIST.editMeeting(params).then((result) => {
      this.loadding = false;
      this.onLoading = false;
      if(result.api_status===true){
        this.meetingId = result.meetingid
        this.type = 'view'
        this.setBaseDetail(true)
        sessionStorage.setItem('type','view')
        sessionStorage.setItem('meetingId',result.meetingid)
        callback();
      }else{
        Bubble.error('提交失败!', 3);
      }
      
    })
  }

  //查看页面直接提交会议
  reSubmit2 = (params,callback)=>{
    this.loadding = true;
    params = this.setFilterReminder(params);
    API_LIST.reSubmit2(params).then((result) => {
      this.loadding = false;
      this.onLoading = false;
      if(result){
        this.meetingId = result.meetingid
        this.type = 'view'
        this.setBaseDetail(true)
        sessionStorage.setItem('type','view')
        if(typeof callback === 'function'){
          callback();
        }
      }else{
        Bubble.error('提交失败!', 3);
      }
      
    })
  }

  //复制会议
  copyMeeting = (params,callback)=>{
    this.loadding  =true;
    API_LIST.copyMeeting(params).then((result) => {
      this.loadding  =false;
      this.onLoading = false;
      if(result.status){
        this.meetingId = result.meetingid
        this.type = 'edit'
        this.setBaseDetail(true)
        sessionStorage.setItem('type','edit')
        sessionStorage.setItem('meetingId',result.meetingid)
        if(typeof callback === 'function'){
          callback();
        }
      }else{
        Bubble.error(getLabel(30651, '操作失败'), 3);
      }
      
    })
  }

  //变更会议
  changemeeting = (params,callback)=>{
    this.loadding = true;
    params = this.setFilterReminder(params);
    API_LIST.changeMeeting(params).then((result) => {
      this.loadding = false;
      this.onLoading = false;
      if(result.status===true){
        this.meetingId = result.meetingid
        this.type = 'view'
        this.setBaseDetail(true)
        sessionStorage.setItem('type','view')
        callback();
      }else{
        Bubble.error(getLabel(30651, '操作失败'), 3);
      }
      
    })
  }

  dateFormat =(fmt, date)=> {
    let ret;
    const opt = {
        "Y+": date.getFullYear().toString(),        // 年
        "m+": (date.getMonth() + 1).toString(),     // 月
        "d+": date.getDate().toString(),            // 日
        "H+": date.getHours().toString(),           // 时
        "M+": date.getMinutes().toString(),         // 分
        "S+": date.getSeconds().toString()          // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
    };
    for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        };
    };
    return fmt;
}

  //提前结束
  overMeeting = (params,callback)=>{
    if(params&&params.overTime == ''){
      Bubble.error(getLabel(384010,'存在必填项未填写'), 3);
    }else{
      API_LIST.overMeeting(params).then((result) => {
        this.onLoading = false;
        if(result.status===true){
          this.getBtns({meetingid:this.meetingId?this.meetingId:sessionStorage.getItem('meetingId')?sessionStorage.getItem('meetingId'):''})
          this.type = 'view'
          this.setBaseDetail(true)
          sessionStorage.setItem('type','view')
          if(typeof callback === 'function'){
            callback();
          }
        }else{
          Bubble.error(getLabel(30651, '操作失败'), 3);
        }
        
      })
    }
  }

  //取消会议
  cancelMeeting = (params,callback)=>{
    API_LIST.cancelMeeting(params).then((result) => {
      this.onLoading = false;
      if(result.status===true){
        if(typeof callback === 'function'){
          callback();
        }
      }else{
        Bubble.error(getLabel(30651, '操作失败'), 3);
      }
      
    })
  }

  //删除会议
  doDelete = (params,callback)=>{
    API_LIST.doDelete(params).then((result) => {
      this.onLoading = false;
      if(result.status===true){
        if(typeof callback === 'function'){
          callback();
        }
      }else{
        Bubble.error(getLabel(30651, '操作失败'), 3);
      }
      
    })
  }

  //批准
  doSubmit = (params,callback)=>{
    this.loadding = true;
    API_LIST.doSubmit(params).then((result) => {
      this.loadding = false;
      this.onLoading = false;
      if(result.status===true){
        this.setBaseDetail(true)
        if(typeof callback === 'function'){
          callback();
        }
      }else{
        Bubble.error(result.error, 3);
      }
    })
  }

  //提交审批
  doSubmit2 = (params,callback)=>{
    this.loadding = true;
    API_LIST.doSubmit2(params).then((result) => {
      this.loadding = false;
      this.onLoading = false;
      if(result.status===true){
        if(typeof callback === 'function'){
          callback();
        }
      }else{
        Bubble.error(result.error, 3);
      }
      
    })
  }

  //退回
  doReject = (params,callback)=>{
    API_LIST.doReject(params).then((result) => {
      this.onLoading = false;
      if(result.status===true){
        if(typeof callback === 'function'){
          callback();
        }
      }
    })
  }

  //提交审批
  reSubmit = (params,callback)=>{
    this.loadding = true;
    API_LIST.reSubmit(params).then((result) => {
      this.loadding = false;
      this.onLoading = false;
      if(result.status===true){
        if(typeof callback === 'function'){
          callback();
        }
      }else{
        Bubble.error(result.error, 3);
      }
      
    })
  }

  getTopic = (params, callback, callback2) => {
    this.topicList.clearData();
    this.topicList.getDataCustom(params);
  }

  // getService = (params, callback, callback2) => {
  //   this.serviceList.clearData();
  //   this.serviceList.getDataCustom(params);
  // }

  getSeatInfo = (params, callback)=>{
    this.seatDatas = [];
    this.seatConfMap = [];
    API_LIST.getSeatInfo(params).then((result)=>{
      this.seatForm = new Form.Store({
        route: '/calendar/detail/meetingSeatData'
      });
      if(result.arrangeSeat){
        let symbolIndex = 0;
        let fieldTemp = result.fieldList;
        fieldTemp.forEach((v,index)=>{
          if(v.key==='seatSymbol'){this.fieldList = v.items;symbolIndex = index;}
        })
        fieldTemp.splice(symbolIndex,1);
        if(fieldTemp[0].items[0].options.length===1){
          fieldTemp[0].items[0].viewAttr=1
        }
        this.seatForm.initForm(fieldTemp, '/calendar/detail/meetingSeatData');
        this.seatDatas = result.seatDatas&&JSON.parse(result.seatDatas);
        this.seatConfMap = result.seatConfMap&&JSON.parse(result.seatConfMap);
        this.hrmNameMap = result.hrmNameMap;
        this.fieldList&&this.fieldList.forEach((key,index)=>{
          if(key['key']==='-2')this.definedColor = key['bgcolor'];
          if(key['key']==='-3')this.selfColor = key['bgcolor'];
        })
        this.selfId = result.selfId;
        this.styleType = result.styleType;
      }
      
    })
  }

  changeBroserMeetingType = (params) => {
    this.meetingType = params.meetingtype;
    return API_LIST.changeBroserMeetingType(params)
  }

  getMember = (params, callback, callback2) => {
    params = { ...params,
      ismobile: 1,
      meetingid:this.meetingId,
      memberType:this.memberType,
      selectType:this.selectType
    };
    API_LIST.getMemberList(params).then((result) => {
      if(this.memberType === 1){
        this.hrmList.setState(result.hrmDatas)
      }else if(this.memberType === 2){
        this.crmList.setState(result.crmDatas)
      }
      
    })
  }

  getMemberCount = (params, callback, callback2) => {
    params = { ...params,
      ismobile: 1,
      meetingid:this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
    };
    API_LIST.getMemberCount(params).then((result) => {
      this.memberDetailCount = result.data;
      this.othersremark = result.othersremark;
      this.othermembers = result.othermembers;
    })
  }

  getOtherMemberDetail = (params, callback, callback2) =>{
    const {memberType} = params;
    API_LIST.getOtherMemberDetail(params).then((result) => {
      if(memberType === '1'){
        this.otherMemberList.setState(result)
      }else{
        this.otherCrmList.setState(result)
      }
      
    })
  }

  getReceiptForm = (params) =>{
    params = { ...params,
      meetingId: this.meetingId,
      recordid:this.recordId,
      isPreview:this.isPreview,
      ismobile: 1
    };
    API_LIST.getMemberReceipt(params).then((result) => {
      this.receiptForm = new Form.Store({
        route: this.prePathName
      });
      this.receiptForm.initForm(result.fields, this.prePathName);
      this.crmReceiptEditable = new ListEditable.Store({ route: this.prePathName });
      // this.receiptForm.setState(result.fields);
    })
  }

  //获取客户回执editTable的编辑condition
  getReceiptCrmCondition = (params)=>{
    params = { ...params,
      meetingid: this.meetingId,
      ismobile: 1
    };
    API_LIST.getReceiptCrmCondition(params).then((result) => {
      this.crmReceiptConditions = result.conditioninfo[0].items
    })
  }

  //查看客户详情
  getReceiptCrmList = (params)=>{
    params = { ...params,
      meetingid: this.meetingId,
      memberType:'2',
      recordid:this.recordId,
      ismobile: 1,
    };
    API_LIST.getReceiptCrmList(params).then((result) => {
      if(result.data){
        this.crmReceiptList.setState(result);
        this.crmReceiptData = result.data;
        this.crmReceiptInitialData = result.data;
      }
    })
  }

  setCrmReceiptData=(params)=>{
    this.crmReceiptData = params
  }

  submitReceipt = (params,callback) =>{
    params = { ...params,
      recorderid:this.recordId,
      meetingid: this.meetingId,
    };
    if(this.memberType === 1){
      API_LIST.submitHrmReceipt(params).then((result) => {
        if(result.status === true){
          Bubble.success(getLabel(83885, '操作成功!'), 1);
          let tempShowReceipt = this.showReceipt;
          tempShowReceipt.canView=true;
          tempShowReceipt.canSubmit=false;
          this.showReceipt= tempShowReceipt
          setTimeout(() => {
            callback();
          }, 1000);
        }
      })
    }else if(this.memberType === 2){
      API_LIST.submitCrmReceipt(params).then((result) => {
        if(result.status === true){
          Bubble.success(getLabel(83885, '操作成功!'), 1);
          let tempShowReceipt = this.showReceipt;
          tempShowReceipt.canView=true;
          tempShowReceipt.canSubmit=false;
          this.showReceipt= tempShowReceipt
          setTimeout(() => {
            callback();
          }, 1000);
        }
      })
    }
    
  }

  getSign = (params, callback, callback2) => {
    API_LIST.getSignList(params).then((result) => {
      let signSessionKey = {
        dataKey: result.sessionkey
      }
      this.signList.getData(signSessionKey)
      this.qrCode = result.qrcode;
    })
  }

  getSignCount = (params, callback, callback2) => {
    params = { ...params,
      ismobile: 1,
      meetingid:this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
    };
    if (this.isSignOut) {
      params = {
        ...params,
        isSignOut: this.isSignOut
      };
    }
    API_LIST.getSignCount(params).then((result) => {
      if (result.data) {
        this.signDetailCount = {
          ...result.data,
          notSignBackCount: result.data.attend - result.data.signBackCount
        };
      }
      this.qrCode = result.qrcode;
    })
  }

   // getSignList = (params, callback, callback2) => {
  //   params = { ...params,
  //     ismobile: 1,
  //     meetingid:this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
  //     selectType:this.signSelectType
  //   };
  //   this.signList = new ListPage.Store();
  //   API_LIST.getSignList2(params).then((result) => {
  //     this.signList.setState(result.signDatas)
  //   })
  // }

  getSignList = (params, callback, callback2) => {
    params = { ...params,
      ismobile: 1,
      meetingid:this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
      selectType:this.signSelectType
    };
    this.signList = new ListPage.Store();
    API_LIST.getSignList2(params).then((result) => {
      this.signList.setState({
        data:result.signDatas.data.map((item,index)=>{
          let keys = Object.keys(item)
          if(_.includes(keys, "backSite")){
            return {
              ...item,
              templateType:"tpk3"
            }
          }else if(_.includes(keys, "site")){
            return {
              ...item,
              templateType:"tpk2"
            }
          }else{
            return {
              ...item,
              templateType:"tpk1"
            }
          }
        })
      })
    })
  }

  getQrCode = (params, callback) => {
    params = { ...params,
      ismobile: 1
    };
    return API_LIST.getQrCode(params)
  }

  //获取最新签到信息
  getLastlySignList = (params, callback, callback2) => {
    params = { ...params,
      ismobile: 1,
      meetingid:this.meetingId,
      selectType:this.signSelectType
    };
    API_LIST.getSignList2(params).then((result) => {
      this.lastlySignList.setState(result.signDatas)
    })
  }

  setPageNum = (val) => {
    this.pageNum = val;
  }

  getComment = (params) => {
    this.pageNum = this.pageNum + 1;
    return Tools.callApi({
      url: '/api/meeting/exchange/getExchangeList',
      method: 'POST',
      params: {
        meetingid: this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
        ismobile: '1',
        isfromchatshare:this.isfromchatshare,
        sharer:this.sharer,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      },
    }).then(action((res) => {
      if(Array.isArray(res.replyList)) {// 过滤内容中的a标签
        res.replyList = res.replyList.map(v => {
          let contentStr = `${Base64.decode(v.content)}`;
          contentStr = contentStr.replace(/<\/?a(.*?)>/g, '');
          v.content = Base64.encode(contentStr);
          return v;
        });
      }
      res.error && res.error === 'noright' && this.setState({noRight: true,noData:false,noSecretRight:false})
        res.error && res.error === 'noData' && this.setState({noRight: false,noData:true,noSecretRight:false})
        res.error && res.error === 'noSecretRight' && this.setState({noRight: false,noData:false,noSecretRight:true})
        if(!res.error){
          this.userName = res.userName;
          this.meetingName = res.meetingName;//用作发送消息通知,当从外部根据isDiscuss单独打开相关交流的时候是没有meetingName这个字段的
          return res
        }
    }))
  }

  getExchangeHrmList= (params)=>{
    return API_LIST.getExchangeHrmList(params).then((result) => {
      this.exchangeListStore = new ListPage.Store({route:'/calendar/detail/discussData/exchangeHrmList'});
      this.exchangeListStore.setState({data:result.atList});
    })
  }

  @action('回复组件的显隐')
  setReplyVisible = (x) => {
    this.replyVisible = x;
  }

  submitReply = (datas) => {
    let cusValue = '';
    let docValue = '';
    let wfValue = '';
    let proValue = '';
    let uploadValue = '';
    datas.attach&&datas.attach.customer&&datas.attach.customer.forEach((element, index) => {
      cusValue += cusValue===''?element.id:','+element.id
    });
    datas.attach&&datas.attach.doc&&datas.attach.doc.forEach((element, index) => {
      docValue += docValue===''?element.id:','+element.id
    });
    datas.attach&&datas.attach.workflow&&datas.attach.workflow.forEach((element, index) => {
      wfValue += wfValue===''?element.id:','+element.id
    });
    datas.attach&&datas.attach.project&&datas.attach.project.forEach((element, index) => {
      proValue += proValue===''?element.id:','+element.id
    })
    datas.attach&&datas.attach.upload&&datas.attach.upload.forEach((element, index) => {
      uploadValue += uploadValue===''?element.id:','+element.id
    })
    let params = {
      remark: datas.text,
      meetingid: this.meetingId,
      //相关客户
      relatedcus :cusValue,
      //相关文档
      docids :docValue,
      //相关流程
      relatedwf :wfValue,
      //相关附件
      relateddoc :uploadValue,
      //相关项目
      projectIDs :proValue,
    }
    this.replySubmitLoading = true;
    API_LIST.submitReply(params).then((result) => {
      this.replySubmitLoading = false;
      if(result.status === true){
        this.pageNum = 0;
        this.comment.getDatas();
        this.reply.doClear();
        Bubble.success(getLabel(83885, '操作成功!'), 1);
        this.replyVisible = false;
      }
    })
    //发送消息通知
    // const atLists = this.reply.getAtList();
    // if(atLists.length > 0){
    //   let uids = [];
    //   atLists.forEach((data,index)=>{
    //     uids.push(data.id)
    //   })
    //   API_LIST.pushMessage({
    //     title: this.meetingName,
    //     context: `${this.userName}：<p>${datas.text}`,
    //     groupCode: "2103",
    //     linkurl: `/spa/meeting/static/index.html#/main/meeting/dialogsingle?meetingid=${this.meetingId}&isDiscuss=1`,
    //     linkMobileUrl: `/spa/meeting/static4mobile/index.html#/calendar/detail?meetingid=${this.meetingId}&isDiscuss=1`,
    //     userid: uids.join(",")
    //   })
    // }
    
  }

  getReplyAttachList = ()=> {
    return Tools.callApi({
      url: '/api/meeting/exchange/getExchangeAttach',
      method: 'POST',
      params: {
        meetingid: this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
        ismobile: '1'
      },
    }).then(action((res) => {
      let attachList = [];
      if(res.relatedwf){
        attachList.push({
          key: 'workflow', // 字符串
          type: 'browser',
          path:'/calendar/detail/discussData/browser',
          config: {
            type: 16,
            isSingle: false,
            hasAdvanceSerach: true,
            dataParams:{
              secretLevel: res.secretLevel
            }
          },
          iconType: 'flow',
          iconBgColor: '#61A8F5',
          text: getLabel(30045, '流程'),
        })
      }
      if(res.docids){
        attachList.push({
          key: 'doc', // 字符串
          type: 'browser',
          path:'/calendar/detail/discussData/browser',
          config: {
            type: 37,
            isSingle: false,
            hasAdvanceSerach: true,
            dataParams:{
              secretLevel: res.secretLevel
            }
          },
          iconType: 'file',
          iconBgColor: '#F3B04C',
          text: getLabel(22243, '文档'),
        })
      }
      if(res.relatedcus){
        attachList.push({
          key: 'customer', // 字符串
          type: 'browser',
          path:'/calendar/detail/discussData/browser',
          config: {
            type: 18,
            isSingle: false,
            hasAdvanceSerach: true,
            dataParams:{
              secretLevel: res.secretLevel
            }
          },
          iconType: 'blog-personal',
          iconBgColor: '#B32E37',
          text: getLabel(136, '客户'),
        })
      }
      if(res.relatedprj){
        attachList.push({
          key: 'project', // 字符串
          type: 'browser',
          path:'/calendar/detail/discussData/browser',
          config: {
            type: 135,
            isSingle: false,
            hasAdvanceSerach: true,
            dataParams:{
              secretLevel: res.secretLevel
            }
          },
          iconType: 'task-list',
          iconBgColor: '#F3B04C',
          text: getLabel(101, '项目'),
        })
      }
      if(res.relateddoc){
        attachList.push({
          key: 'upload', // 字符串
          type: 'upload',
          path:'/calendar/detail/discussData/upload',
          config: {
            ...res.relateddoc
          },
          iconType: 'file',
          iconBgColor: '#F3B04C',
          text: getLabel(156, '附件'),
        })
      }
      return {attachList:attachList};
    }))
  }

  getAtConfig = () => (
    new Promise((resolve) => {
      resolve({
        atConfig: {
          key: 'at',
          path: '/calendar/detail/discussData',
          config: {
            type: 1,
            isSingle: true,
          },
        },
      });
    })
  )


  onReceiptEdit = (params) =>{
    API_LIST.submitHrmReceipt(params).then((result) => {
      Bubble.success(getLabel(83885, '操作成功!'), 1);
    })
  }

  chkMeeting = (params)=>(
    API_LIST.chkMeeting(params)
  )

  customMeetingChk = (params)=>(
    API_LIST.customMeetingChk(params)
  )

  getDecisionForm = (params)=>{
    params = { ...params,
      meetingid: this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
      isView:this.isView,
      ismobile: 1
    };
    API_LIST.getDecisionBaseData(params).then((result) => {
      this.decisionForm = new Form.Store({
        route: '/calendar/detail/decision/index'
      });
      this.decisionForm.initForm(result.conditioninfo,  '/calendar/detail/decision/index');
    })
  }

  getSignCreateSet = (params)=>{
    API_LIST.getSignCreateSet(params).then((result) => {
      this.signCreateForm = new Form.Store({
        route: '/calendar/detail/signcreate'
      });
      this.signCreateForm.initForm(result.fields,  '/calendar/detail/signcreate');
    })
  }

  saveSignCreateSet = (params,callback)=>{
    params = { ...params,
      meetingid: this.meetingId?this.meetingId:sessionStorage.getItem('meetingId')
    };
    API_LIST.saveSignCreateSet(params).then((result) => {
      if(result.api_status === true){
        Bubble.success(getLabel(83885, '操作成功!'), 1);
        setTimeout(() => {
          callback();
        }, 1000);
      }
    })
  }


  //获取editTable的编辑condition
  getDecisionCondition = (params)=>{
    params = { ...params,
      meetingid: this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
      isView:this.isView,
      ismobile: 1
    };
    API_LIST.getDecisionCondition(params).then((result) => {
      this.decisionConditions = result.conditioninfo[0].items
    })
  }

  //查看会议决议任务
  getDecisionList = (params)=>{
    params = { ...params,
      meetingid: this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
      isView:this.isView,
      ismobile: 1
    };
    API_LIST.getDecisionList(params).then((result) => {
      if(result.data){
        this.decisionList.setState(result);
        this.decisionData = result.data;
        this.decisionInitialData = result.data;
      }
    })
  }

  editDecision = (params,callback)=>{
    params = { ...params,
      meetingid: this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
      isView:this.isView,
      ismobile: 1
    };
    API_LIST.editDecision(params).then((result) => {
      if(result.status){
        if(typeof callback === 'function'){
          callback();
        }
      }
    })
  }

  submitDecision = (params,callback)=>{
    params = { ...params,
      meetingid: this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
      isView:this.isView,
      ismobile: 1
    };
    API_LIST.submitDecision(params).then((result) => {
      if(result.status){
        this.getBtns({meetingid:this.meetingId?this.meetingId:sessionStorage.getItem('meetingId')?sessionStorage.getItem('meetingId'):''})
        if(typeof callback === 'function'){
          callback();
        }
      }
    })
  }

  setDecisionData=(params)=>{
    this.decisionData = params
  }

  groupToggleForm = (...arg) => {
    let title = arg[0];
    let status = arg[1];
    this.form.conditioninfo = this.form.conditioninfo.map(res => ({
      ...res,
      ...(res.title === title ? {show: status} : {})
    }));
  }

  groupToggleDecisionForm = (...arg) => {
    let title = arg[0];
    let status = arg[1];
    this.decisionForm.conditioninfo = this.decisionForm.conditioninfo.map(res => ({
      ...res,
      ...(res.title === title ? {show: status} : {})
    }));
  }

  groupToggleReceiptForm = (...arg) => {
    let title = arg[0];
    let status = arg[1];
    this.receiptForm.conditioninfo = this.receiptForm.conditioninfo.map(res => ({
      ...res,
      ...(res.title === title ? {show: status} : {})
    }));
  }

  //cx新加部分   start
  

  initTopicList = (callback)=>{
    let formListTemp = this.topic_list?this.topic_list.formList:{}
    Object.keys(formListTemp).forEach(_k=>{
      formListTemp[_k].isInit = false;
    })
    this.topic_list = new ListEditable.Store({ route: '/calendar/detail/topicData' });
    this.topic_list.setState({formList:formListTemp});
    typeof callback === 'function' && callback();
  }

  initServiceList = ()=>{
    const formListTemp = this.service_list?this.service_list.formList:{}
    Object.keys(formListTemp).forEach(_k=>{
      formListTemp[_k].isInit = false;
    })
    this.service_list = new ListEditable.Store({ route: '/calendar/detail/serviceData' });
    this.service_list.setState({formList:formListTemp})
  }

  get_Conditions = (params, type, callback) => {
    if(type === 'topic'){
      params ={
        ...params,
      };
      if(this.type === 'view' && this.topicType === 'view') {
        params.isView = true;
      } else {
        params.isView = false;
      }
      API_LIST.getTopic_Condition(params).then(res => {
        this.topic_conditions = [];
        this.topic_conditions = res.conditioninfo && res.conditioninfo[0] && res.conditioninfo[0].items && this.setTopicAndServiceSecretLevel(res.conditioninfo[0].items,res.topicDocFlowColumn);
        this.topicViewTopicConditions = [...this.topic_conditions];
        this.topicViewTopicConditions.push(
          {
            domkey: ['defined_btns']
          }
        );
        this.topicDocFlowColumn = res.topicDocFlowColumn;
        this.overWriteDocAndWF(res.conditioninfo,params);
        if(res && res.conditioninfo && res.conditioninfo[0] && res.conditioninfo[0].items) {
          let tempArr = res.conditioninfo[0].items;
          this.topicConditionUploadKeys = [];
          Array.isArray(tempArr) && tempArr.forEach(t => {
            if(t.conditionType === "UPLOAD") {
              if(t.domkey) {
                this.topicConditionUploadKeys.push( t.domkey[0] );
              }
            }
          });
        }
        typeof callback === 'function' && callback();
      });
    }
    if(type === 'service'){
      this.service_conditions = [];
      API_LIST.getService_Condition(params).then(res => {
        this.service_conditions = res.conditioninfo && res.conditioninfo[0] && res.conditioninfo[0].items && this.setTopicAndServiceSecretLevel(res.conditioninfo[0].items,res.serviceDocFlowColumn);
        this.serviceDocFlowColumn = res.serviceDocFlowColumn;
        this.overWriteDocAndWF(res.conditioninfo,params);
        if(res && res.conditioninfo && res.conditioninfo[0] && res.conditioninfo[0].items) {
          let tempArr = res.conditioninfo[0].items;
          this.serviceConditionUploadKeys = [];
          Array.isArray(tempArr) && tempArr.forEach(t => {
            if(t.conditionType === "UPLOAD") {
              if(t.domkey) {
                this.serviceConditionUploadKeys.push( t.domkey[0] );
              }
            }
          });
        }
      });
    }
  }

  //设置明细支持密级字段筛选
  setTopicAndServiceSecretLevel = (items,columns)=>{
      items.forEach((field) => {
        if(columns && columns.includes(field.domkey[0]) && field.conditionType === 'BROWSER'){
          field.browserConditionParam.dataParams = {...field.browserConditionParam.dataParams,secretLevel: this.oldSecretLevel}
          field.browserConditionParam.completeParams = {...field.browserConditionParam.completeParams,secretLevel: this.oldSecretLevel}
        }
      })
      return items;

  }



  get_Data = (params, type ) => {
    this.loadding = true;
    if(type === 'topic'){
      if(this.type === 'view' && this.topicType === 'view') {
        params.isView = true;
      } else {
        params.isView = false;
      }
      API_LIST.getTopic_Data(params).then(res => {
        this.loadding = false;
        this.topicList = new ListPage.Store({ route: '/calendar/detail/topicData' });
        this.topicList.setState(res);
        
        if(this.topic_initialData && this.topic_initialData.length == 0){
          this.topic_initialData = res.data;
          this.topic_data = res.data;
        }
        if(this.type === 'view') {
          this.topic_data = res.data;
        }
      });
    }
    if(type === 'service'){
      API_LIST.getService_Data(params).then(res => {
        this.loadding = false;
        this.serviceList = new ListPage.Store({ route: '/calendar/detail/serviceData' });  
        this.serviceList.setState(res);
        if(this.serivce_initialData && this.serivce_initialData.length == 0){
          this.serivce_initialData = res.data;
          this.serivce_data = res.data;
        }
        if(this.type === 'view') {
          this.serivce_data = res.data;
        }
        this.serviceKeycol = res.keycol;
      });
    }
  }

  // 获取签退人员信息列表
  // getSignBackList4mobile = (params) => {
  //   params = { ...params,
  //     ismobile: 1,
  //     meetingid:this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
  //     selectType:this.signSelectType
  //   };
  //   API_LIST.getSignBackList4mobile(params).then(res => {
  //     this.signList.setState(res.signDatas);
  //   });
  // }

  getSignBackList4mobile = (params) => {
    params = { ...params,
      ismobile: 1,
      meetingid:this.meetingId?this.meetingId:sessionStorage.getItem('meetingId'),
      selectType:this.signSelectType
    };
    API_LIST.getSignBackList4mobile(params).then(res => {
      this.signList.setState({
        data:res.signDatas.data.map((item,index)=>{
          let keys = Object.keys(item)
          if(_.includes(keys, "backSite")){
            return {
              ...item,
              templateType:'tpk3'
            }
          }else if(_.includes(keys, "site")){
            return {
              ...item,
              templateType:'tpk2'
            }
          }else{
            return {
              ...item,
              templateType:'tpk1'
            }
          }
        })
      });
    });
  }


  //cx新加部分   end

  // 获取服务项目相关的负责人员 -选择服务带出服务人员
  getService_project_hrminfo = (params) => {
    API_LIST.getService_project_hrminfo(params).then(res => {
      if(res && res.api_status) {
        if(Array.isArray(toJS(this.serivce_data))) {
          this.serivce_data = this.serivce_data.map(v => {
            if (this.service_list.editingKey === v.id) {
              return {
                ...v,
                hrmids_47: res.hrmids,
                hrmids_47span: res.hrmNames
              }
            }else{
              return v;
            }
          })
        }
      }
    })
  }

  //获取签到/签退时间 QC727172===============start
  @observable position=[]
  @observable address=""

  @observable
  signTimeStatus = {
    defaultAllowSignTime:"",
    defaultAllowSignBackTime:""
  }
  @observable
  toSetSignTime = false

  @action
  getDefaultSignBackTime = (callback)=>{
    API.getDefaultSignBackTime({meetingid:this.meetingId}).then(res=>{
      if(res&&res.api_status){
        if(res.fields&&res.fields[0].items){
          this.signTimeStatus={
            defaultAllowSignTime:res.fields[0].items[0]['value'],
            defaultAllowSignBackTime:res.fields[0].items[1]["value"],
          }
          this.toSetSignTime=true;
        }
      
      }
    })
    this.toSetSignTime=false;
  }

  @action
  setSignTimeStatus=(params={})=>{
    Object.keys(params).forEach((key) => {
      this.signTimeStatus[key] = params[key];
    });
  }
  //获取签到/签退时间 QC727172===============end

  overWriteDocAndWF = (dataTemp,params={})=>{
    dataTemp.forEach((group) => {
      group.items.forEach((field) => {
        if(field.conditionType == 'UPLOAD'){// 没有必要再重新写一个方法专门设置查看状态下的upload参数，浪费资源
          this.uploadParams = {
            ...this.uploadParams,
            [field.domkey[0]]: {
              autoUpload: field.autoUpload || true,
              listType: field.listType || 'list',
              limitType: field.limitType || '',
              uploadUrl: field.uploadUrl || '',
              maxUploadSize: field.maxUploadSize || 0,
              mixUploadSize: field.mixUploadSize || 0,
              viewAttr: field.viewAttr || 2,
              showClearAll: field.showClearAll || false,
              category: field.category || '',
              errorMsg: field.errorMsg || '',
              datas: field.datas || [],
            }
          }
          this.uploadKeys = [...this.uploadKeys, field.domkey[0]]
        }
        if(field&&field.conditionType&&field.conditionType==='BROWSER'&&(field.browserType==='9'||field.browserType==='37')){
          if(window.openLink && window.openLink.openDocument&&!this.overWriteOpenDoc){
            let meetingidTemp = params.meetingid
            window.openLink.openDocument = function () {
              return function (docId, params2, type) {
                var search = "";
                var url = "/spa/document/static4mobile/index.html#/doc/" + docId + '?meetingid='+meetingidTemp;
                window.openLink(url, type)
              }
            }();
            this.overWriteOpenDoc = true;
          }
        }
        if(field&&field.conditionType&&field.conditionType==='BROWSER'&&(field.browserType==='16'||field.browserType==='152')){
          if(window.openLink && window.openLink.openWorkflow&&!this.overWriteOpenWF){
            let meetingIdTemp = params.meetingid
            window.openLink.openWorkflow = function () {
              return function (url, callbackFun, returnUrl) {
                if (window.em && typeof window.em.checkJsApi === "function" && window.em.checkJsApi("openLink") && window.em.checkJsApi("closeWindow") && window.navigator.userAgent.indexOf("E-Mobile") > -1) {
                  var title = "表单详情";
                  if (window.e9_locale && window.e9_locale.label) {
                    title = window.e9_locale.label[500244] || "表单详情";
                  }
                  url = url + '&fromModul=meeting&modulResourceId='+meetingIdTemp
                  window.em.openLink({
                    openType: 2,
                    title: title,
                    url: url
                  });
                  if (typeof callbackFun === "function") {
                    window.em.ready(function(){
                      window.em.registerBroadcast({
                        name: "_closeWfFormCallBack",
                        action: function (argument) {
                          if (typeof argument === "string") {
                            argument = JSON.parse(argument);
                          }
                          callbackFun(argument.text);
                        }
                      });
                    });
                  }
                } else {
                  //window.open(url);   //微信、钉钉客户端open就等于location.href
                  window.location.href = url+'&fromModul=meeting&modulResourceId='+meetingIdTemp;
                  if (returnUrl === "") {
                    returnUrl = window.location.href;
                    if (returnUrl.indexOf("/spa") > -1) {
                      returnUrl = returnUrl.substr(returnUrl.indexOf("/spa"));
                    }
                  }
                  sessionStorage.setItem("__wf__openform__returnurl__", returnUrl);
                  if (typeof callbackFun === "function") {
                    window.__closeFormCallBack = callbackFun;
                  }
                }
              }
            }();
            this.overWriteOpenWF = true;
          }
        }
      })
    })
  }

  // 议程资料保存
  addTopicDoc = (params, callback) => {
    API_LIST.addtopicdoc(params).then(res => {
      typeof callback === 'function' && callback();
    });
  }
  
  // 议程资料删除
  delTopicDoc = (params, callback) => {
    API_LIST.deltopicdoc(params).then(res => {
      typeof callback === 'function' && callback();
    });
  }

  // 获取议程资料
  getTopicDocList = (params, callback) => {
    this.topicDocList = [];
    API_LIST.getTopicDocList(params).then(res => {
      if(res.api_status) {
        this.topicDocList = res.data;
        this.datumForm.initForm(res.data, '/calendar/detail/topicData/videwDatumLayout');
      }
      typeof callback === 'function' && callback();
    });
  }

  // 获得时间安排数据
  getTopicDate = (params, callback) => {
    API_LIST.getTopicDate(params).then(res => {
      if(res.api_status) {
        let date = [];
        Array.isArray(res.data) && res.data.map((res, index) => {
          date.push({
            id: index,
            date: [
              `${res.begindate} ${res.begintime}`,
              `${res.enddate} ${res.endtime}`
            ],
          });
        });
        this.topicArrangeDates = date;
      }
      typeof callback === 'function' && callback();
    });
  }

  // 获取议程资料
  saveTopicDate = (params, callback) => {
    API_LIST.saveTopicDate(params).then(res => {
      if(res.api_status) {
        Bubble.success(getLabel(83885, '操作成功!'), 1);
        typeof callback === 'function' && callback();
      } else {
        Bubble.error(getLabel(30651, '操作失败'), 1);
      }
    });
  }

  // 获取议程资料
  saveTopicTidy = (params, callback) => {
    API_LIST.saveTopicTidy(params).then(res => {
      if(res.api_status) {
        Bubble.success(getLabel(83885, '操作成功!'), 1);
        typeof callback === 'function' && callback();
      } else {
        Bubble.error(getLabel(30651, '操作失败'), 1);
      }
    });
  }


}

